This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
## ggplot2 dplyr lubridate reshape2 magrittr stringi tidyr
## TRUE TRUE TRUE TRUE TRUE TRUE TRUE
## ggmap ggthemes scales RSocrata
## TRUE TRUE TRUE TRUE
## dplyr lubridate reshape2 RSocrata
## TRUE TRUE TRUE TRUE
Using the https://data.austintexas.gov & the Socrata API, we’ll pull some data from Austin Police Department (APD). This is a large dataset, so we’ll leave eval = FALSE
# Pull form API
# ReportsAPD <- RSocrata::read.socrata("https://data.austintexas.gov/resource/b4y9-5x39.csv")
# Write as CSV
# write.csv(x=ReportsAPD, file = "ReportsAPD.csv")
Select the columns that are of interest to us, and create a factor for the ‘Crime’ variable. The result is a data frame called ‘APD’
Crimes occuring greater than 1000 times this year
APD %>% group_by(Crime) %>%
mutate(number_of_calls = n()) %>% arrange(desc(number_of_calls)) %>%
filter(number_of_calls > 1000, year(Date) == 2015 ) %>%
ggplot(aes(x=Crime, y=Date, group=Crime, fill=number_of_calls)) +
geom_violin(alpha=I(0.75)) + geom_point(alpha=I(0.75), size=I(0.1)) +
coord_flip() + theme_fivethirtyeight() + scale_fill_continuous(low="yellow", high = "red")
Crimes occuring between 500 and 1000 times this year
APD %>% group_by(Crime) %>%
mutate(number_of_calls = n()) %>% arrange(desc(number_of_calls)) %>%
filter(number_of_calls < 1000, number_of_calls > 500, year(Date) == 2015 ) %>%
ggplot(aes(x=Crime, y=Date, group=Crime, fill=number_of_calls)) +
geom_violin(alpha=I(0.75)) + geom_point(alpha=I(0.75), size=I(0.1)) +
coord_flip() + theme_fivethirtyeight() + scale_fill_continuous(low="yellow", high = "red")
Crimes occuring between 100 and 500 times this year
APD %>% group_by(Crime) %>%
mutate(number_of_calls = n()) %>% arrange(desc(number_of_calls)) %>%
filter(number_of_calls < 500, number_of_calls > 100, year(Date) == 2015 ) %>%
ggplot(aes(x=Crime, y=Date, group=Crime, fill=number_of_calls)) +
geom_violin(alpha=I(0.75)) + geom_point(alpha=I(0.75), size=I(0.1)) +
coord_flip() + theme_fivethirtyeight() + scale_fill_continuous(low="yellow", high = "red")